package com.gxc;

import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import java.net.URLConnection;
import java.nio.charset.StandardCharsets;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import java.util.zip.ZipInputStream;

/**
 * @author 宫新程
 * @since 2019/3/4 17:56
 */
public class zip {

  private static String FILE_NAME =  "http://img.yilihuo.com/group1/M00/1C/37/oYYBAFx89oSAXAP7AAAWN6MVn7s997.zip";

  public static void main(String[] args) throws Exception {
    try {

      readZipFile(FILE_NAME);

    } catch (Exception e) {
      e.printStackTrace();
    }
  }

  public static void readZipFile(String file) throws Exception {
    URL url = new URL(FILE_NAME);
    HttpURLConnection conn = (HttpURLConnection) url.openConnection();
    conn.setDoInput(true);
    conn.setDoOutput(true);
    conn.setRequestMethod("GET");

    InputStream inputStream = conn.getInputStream();

//    ZipFile zf = new ZipFile(file);
    InputStream in = new BufferedInputStream(inputStream);
    ZipInputStream zin = new ZipInputStream(in);
    ZipEntry ze;
    while ((ze = zin.getNextEntry()) != null) {
      if (ze.isDirectory()) {
      } else {
        System.err.println("file - " + ze.getName() + " : "
            + ze.getSize() + " bytes");
        long size = ze.getSize();
//        if (size > 0) {
//          BufferedReader br = new BufferedReader(
//              new InputStreamReader(zf.getInputStream(ze)));
//          String line;
//          while ((line = br.readLine()) != null) {
//            System.out.println(line);
//          }
//          br.close();
//        }
        System.out.println();
      }
    }
    zin.closeEntry();
  }

}
